<template>
  <div class="app-container">
    <div class="div-style" style="height: 300px">
      <template-master :query-params="queryParams" :refresh-key="refreshKey" :tr-disabled="false"
                       @row-click="rowClick"/>
    </div>
    <div class="mt10 div-style">
      <template-item ref="templateItemRef" :apply-item="applyItem" :detail-is-show="detailIsShow"
                     :is-show="false" :query-params="queryParams" @quote-ok="quoteOk"/>
    </div>
  </div>
</template>

<script lang="ts" setup>
import templateMaster from "./templateMaster.vue"
import templateItem from "./templateItem.vue"

const emits = defineEmits(["quoteOkIndex"])
const props = defineProps({
  queryParams: {
    type: Object as PropType<TemplateMasterType>,
  },
  refreshKey: {
    type: Number,
    default: 0
  },
})
const templateItemRef = ref()
const detailIsShow = ref<any>("1")

const applyItem = ref({})
function rowClick(row: any) {
  row.isQuote = true
  applyItem.value = row
  detailIsShow.value = props.queryParams?.showItemClass
  row.showItemClass = props.queryParams?.showItemClass
  row.storageId =  props.queryParams?.storageId
  nextTick(() => {
    templateItemRef.value.rowClick(row)
  })
}

// 模板引用 -》 最终数据处理
function quoteOk(list: any) {
  emits("quoteOkIndex", list)
}

function emptyPrescriptionItemList() {
  nextTick(() => {
    templateItemRef.value.emptyPrescriptionItemList()
  })
}

defineExpose({
  emptyPrescriptionItemList
})
</script>
